<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<script>
    $(function () {
        InitRoleList();
        var stor = $("#rolelistgrid").edatagrid("getPager");
        if (stor) {
            $(stor).pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    var para = $("#rolelistgrid").datagrid("options");
                    para.queryParams = {
                        filter: $("#storefilter").val()
                    };
                    para.pageNumber = pageNumber;
                    para.pageSize = pageSize;
                    $('#rolelistgrid').datagrid('reload');
                }
            });
        }
    });


    function InitRoleList() {
        $("#rolelistgrid").edatagrid({
            title: '角色列表', //列表的标题
            iconCls: 'icon-site',
            width: 'auto',
            singleSelect: true, //是否单选行
            selectOnCheck: true,
            checkOnSelect: true,
            nowrap: true, //True 就会把数据显示在一行里。
            striped: true, //True 就把行条纹化。（即奇偶行使用不同背景色）
            collapsible: true, //可调节列宽
            remoteSort: true, //定义是否从服务器给数据排序。
            url: "<%=basePath%>/system/role/getAllRolesList", //获取数据的url
            columns: [
              [
                        { field: 'name', title: '角色名称', width: '10%', align: 'center' },
                        { field: 'groupName', title: '分组名称', width: '10%', align: 'center' },
                       
                        {
                            field: 'optorder', title: ' ', width: "25%", align: 'center', formatter: function (value, rec, index)
                            {
                                var a = '<a href="javascript:deleterole(\'' + rec.roleId + '\')" mce_href="#">删除</a> ';
                               
                                a += '<a href="javascript:editrole(\'' + rec.roleId + '\')" mce_href="#">编辑</a> ';
                              
                                a += '<a href="javascript:editauthrization(\'' + rec.roleId + '\')" mce_href="#">权限配置</a> ';
                                return a;
                            }
                        }
              ]
            ],
            pagination: true,
            rownumbers: true,
            pageSize: '20'
        });
    }

    function rolequery() {
        $("#rolelistgrid").datagrid("load", {
            name: $("#roleName").val()
        });
    }

    function deleterole(id) {
        ERP_confirm("确定要删除该用户吗？删除后将不能恢复！", function (ret) {
            if (ret) {
                $.get("<%=basePath%>/system/role/deleteRole?id=" + id, function (data) {
                    if (data != "") {
                        ERP_alert(data);
                    }
                    else {
                        ERP_alert('操作成功');
                        rolequery();
                    }
                });
            }
        });
    }
    function editauthrization(id) {
        $('#storedetail').dialog({
            title:'权限',
            width: '30%',
            height: '100%',
            closed: false,
            cache: false,
            href: '<%=basePath%>/system/role/editRoleAuthrization?id=' + id,
            modal: true
        });

    }
    function addrole() {
        $('#storedetail').dialog({
            title: '角色',
            width: 400,
            height: 300,
            closed: false,
            cache: false,
            href: '<%=basePath%>/system/role/editRole',
            modal: true
        });

    }
    function editrole(id) {
        $('#storedetail').dialog({
            title: '角色',
            width: 400,
            height: 300,
            closed: false,
            cache: false,
            href: '<%=basePath%>/system/role/editRole?id='+id,
            modal: true
        });

    }
    function manergroup() {
        $('#storedetail').dialog({
            title: '分组',
            width: 400,
            height: 300,
            closed: false,
            cache: false,
            href: '<%=basePath%>/system/role/roleGroupList',
            modal: true
        });

    }
</script>

<div id="toolbar_filter">
    角色名称：<input id="roleName" class="easyui-textbox" data-options="prompt:'角色名称'" /> &nbsp;&nbsp;
    <a href="javascript:rolequery()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查询</a>
    <a href="javascript:addrole()" class="easyui-linkbutton" >新增</a>
    <a href="javascript:manergroup()" class="easyui-linkbutton">分组管理</a>
</div>

<table id="rolelistgrid"></table>
<div id="storedetail"></div>